//
//  TermsOfServiceViewController.m
//  SnapCAD
//
//  Created by Developer on 2025/1/27.
//

#import "TermsOfServiceViewController.h"
#import "Masonry.h"

@interface TermsOfServiceViewController ()

@property (nonatomic, strong) UIView *headerView;
@property (nonatomic, strong) UIButton *backButton;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UIScrollView *scrollView;
@property (nonatomic, strong) UILabel *contentLabel;

@end

@implementation TermsOfServiceViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupUI];
    [self setupConstraints];
    [self loadTermsOfServiceContent];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:YES animated:animated];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:animated];
}

- (void)setupUI {
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self setupHeader];
    [self setupScrollView];
}

- (void)setupHeader {
    // 头部视图
    self.headerView = [[UIView alloc] init];
    self.headerView.backgroundColor = [UIColor whiteColor];
    
    // 添加阴影
    self.headerView.layer.shadowColor = [UIColor blackColor].CGColor;
    self.headerView.layer.shadowOffset = CGSizeMake(0, 2);
    self.headerView.layer.shadowOpacity = 0.1;
    self.headerView.layer.shadowRadius = 4;
    
    self.headerView.translatesAutoresizingMaskIntoConstraints = NO;
    [self.view addSubview:self.headerView];
    
    // 返回按钮
    self.backButton = [UIButton buttonWithType:UIButtonTypeSystem];
    [self.backButton setImage:[UIImage systemImageNamed:@"chevron.left"] forState:UIControlStateNormal];
    self.backButton.tintColor = [UIColor colorWithRed:0.40 green:0.49 blue:0.93 alpha:1.0];
    [self.backButton addTarget:self action:@selector(backButtonTapped) forControlEvents:UIControlEventTouchUpInside];
    self.backButton.translatesAutoresizingMaskIntoConstraints = NO;
    [self.headerView addSubview:self.backButton];
    
    // 标题标签
    self.titleLabel = [[UILabel alloc] init];
    self.titleLabel.text = @"Terms of Service";
    self.titleLabel.font = [UIFont boldSystemFontOfSize:18];
    self.titleLabel.textColor = [UIColor blackColor];
    self.titleLabel.textAlignment = NSTextAlignmentCenter;
    self.titleLabel.translatesAutoresizingMaskIntoConstraints = NO;
    [self.headerView addSubview:self.titleLabel];
}

- (void)setupScrollView {
    // 滚动视图
    self.scrollView = [[UIScrollView alloc] init];
    self.scrollView.backgroundColor = [UIColor whiteColor];
    self.scrollView.showsVerticalScrollIndicator = YES;
    self.scrollView.translatesAutoresizingMaskIntoConstraints = NO;
    [self.view addSubview:self.scrollView];
    
    // 内容标签
    self.contentLabel = [[UILabel alloc] init];
    self.contentLabel.numberOfLines = 0;
    self.contentLabel.font = [UIFont systemFontOfSize:14];
    self.contentLabel.textColor = [UIColor colorWithRed:0.3 green:0.3 blue:0.3 alpha:1.0];
    self.contentLabel.lineBreakMode = NSLineBreakByWordWrapping;
    self.contentLabel.translatesAutoresizingMaskIntoConstraints = NO;
    [self.scrollView addSubview:self.contentLabel];
}

- (void)setupConstraints {
    // 头部视图约束
    [self.headerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(self.view);
        make.height.equalTo(@88);
    }];
    
    // 返回按钮约束
    [self.backButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.headerView).offset(16);
        make.bottom.equalTo(self.headerView).offset(-10);
        make.size.mas_equalTo(CGSizeMake(44, 44));
    }];
    
    // 标题标签约束
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.headerView);
        make.centerY.equalTo(self.backButton);
    }];
    
    // 滚动视图约束
    [self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.headerView.mas_bottom);
        make.left.right.bottom.equalTo(self.view);
    }];
    
    // 内容标签约束
    [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.scrollView).offset(20);
        make.left.equalTo(self.scrollView).offset(20);
        make.right.equalTo(self.scrollView).offset(-20);
        make.bottom.equalTo(self.scrollView).offset(-20);
        make.width.equalTo(self.scrollView).offset(-40);
    }];
}

- (void)loadTermsOfServiceContent {
    NSString *termsOfService = @"TERMS OF SERVICE\n\nLast updated: January 27, 2025\n\n1. ACCEPTANCE OF TERMS\n\nBy accessing and using SnapCAD (\"the Service\"), you accept and agree to be bound by the terms and provision of this agreement. If you do not agree to abide by the above, please do not use this service.\n\n2. DESCRIPTION OF SERVICE\n\nSnapCAD is a Computer-Aided Design (CAD) application that allows users to view, edit, and manage CAD files. The Service includes:\n\n• CAD file viewing and rendering\n• File management and organization\n• Measurement and annotation tools\n• Unit conversion utilities\n• Cloud storage integration\n• Collaboration features\n\n3. USER ACCOUNTS\n\n3.1 Account Creation\nTo access certain features of the Service, you may be required to create an account. You agree to provide accurate, current, and complete information during the registration process.\n\n3.2 Account Security\nYou are responsible for safeguarding the password and for maintaining the confidentiality of your account. You agree to notify us immediately of any unauthorized use of your account.\n\n3.3 Account Termination\nWe reserve the right to terminate or suspend your account at any time for violations of these terms or for any other reason at our sole discretion.\n\n4. USER CONTENT AND CONDUCT\n\n4.1 User Content\nYou retain ownership of any intellectual property rights that you hold in content you upload to the Service. By uploading content, you grant us a worldwide, non-exclusive, royalty-free license to use, reproduce, and distribute your content solely for the purpose of providing the Service.\n\n4.2 Prohibited Conduct\nYou agree not to:\n• Use the Service for any unlawful purpose or in violation of any applicable laws\n• Upload or transmit viruses, malware, or other malicious code\n• Attempt to gain unauthorized access to the Service or other users' accounts\n• Interfere with or disrupt the Service or servers connected to the Service\n• Use the Service to harass, abuse, or harm others\n\n5. INTELLECTUAL PROPERTY\n\n5.1 Service Content\nThe Service and its original content, features, and functionality are owned by SnapCAD and are protected by international copyright, trademark, patent, trade secret, and other intellectual property laws.\n\n5.2 Trademarks\nSnapCAD, the SnapCAD logo, and other marks are trademarks of our company. You may not use these trademarks without our prior written consent.\n\n6. PRIVACY POLICY\n\nYour privacy is important to us. Please review our Privacy Policy, which also governs your use of the Service, to understand our practices.\n\n7. PAYMENT AND SUBSCRIPTION\n\n7.1 Subscription Plans\nCertain features of the Service may require payment of fees. You agree to pay all applicable fees as described in the Service at the time you subscribe.\n\n7.2 Billing\nSubscription fees are billed in advance on a recurring basis. You authorize us to charge your payment method for all fees.\n\n7.3 Refunds\nRefunds are handled on a case-by-case basis. Please contact our support team for refund requests.\n\n8. DISCLAIMERS\n\n8.1 Service Availability\nWe do not guarantee that the Service will be available at all times. The Service may be subject to limitations, delays, and other problems inherent in the use of the internet and electronic communications.\n\n8.2 Accuracy\nWhile we strive to provide accurate information, we make no warranties about the accuracy, reliability, completeness, or timeliness of the content, services, software, text, graphics, and links.\n\n9. LIMITATION OF LIABILITY\n\nIn no event shall SnapCAD, its officers, directors, employees, or agents be liable for any indirect, incidental, special, consequential, or punitive damages, including without limitation, loss of profits, data, use, goodwill, or other intangible losses.\n\n10. INDEMNIFICATION\n\nYou agree to defend, indemnify, and hold harmless SnapCAD and its licensee and licensors, and their employees, contractors, agents, officers and directors, from and against any and all claims, damages, obligations, losses, liabilities, costs or debt, and expenses (including but not limited to attorney's fees).\n\n11. TERMINATION\n\nWe may terminate or suspend your account and bar access to the Service immediately, without prior notice or liability, under our sole discretion, for any reason whatsoever and without limitation, including but not limited to a breach of the Terms.\n\n12. GOVERNING LAW\n\nThese Terms shall be interpreted and governed by the laws of the State of California, United States, without regard to conflict of law provisions.\n\n13. CHANGES TO TERMS\n\nWe reserve the right, at our sole discretion, to modify or replace these Terms at any time. If a revision is material, we will provide at least 30 days notice prior to any new terms taking effect.\n\n14. CONTACT INFORMATION\n\nIf you have any questions about these Terms of Service, please contact us at:\n\nEmail: legal@snapcad.com\nAddress: SnapCAD Legal Team\n123 Technology Drive\nSan Francisco, CA 94105\nUnited States\n\nBy using our Service, you acknowledge that you have read and understood these Terms of Service and agree to be bound by them.";
    
    self.contentLabel.text = termsOfService;
}

#pragma mark - Button Actions

- (void)backButtonTapped {
    [self.navigationController popViewControllerAnimated:YES];
}

@end